<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>

<script type="text/javascript" src="http://localhost/eclipse/test_php/js/jquery1.7.js">
</script>

<script type="text/javascript">
function myalert() {
	alert("any messege");
}

$("#userID").keyPress(function()
	    {
	    $.ajax(
	        {
	        url: "check.php",
	        type: "GET",//Giả sử là GET đi
	        data: "userID=" + $("#userID").val(),
	        success(data, textStatus, jqXHR)
	            {
	            if(data==true)
	                {
	                $("#status").html("Tên đã tồn tại!");
	                }
	            else if(data==false)
	                {
	                $("#status").html("Tên có thể sử dụng");
	                }
	            }
	        error(jqXHR, textStatus, errorThrown)
	            {
	            alert("Có lỗi xảy ra!");
	            }
	        });
	    });
</script>
<body>
	<input type="button" onclick="myalert()" value="get msg">
	<h2>Valid form use jQuery-Ajax</h2>
	<form action="register.php" method="POST">
		<input type="text" id="userID">
		<span id="status">Please enter your desire ID</span>
		<br>
		<input type="submit" value="REGISTER">
	</form>

	www.ddth.com/showthread.php/525087-Basic-Ajax-jQuery-và-những-điều-cần-biết
</body>
</html>